package array

func countBattleships(board [][]byte) int {

	m := len(board)
	n := len(board)
	res := 0

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {

			if board[i][j] == 'X' {

				flag := false
				board[i][j] = '.'
				for k := j + 1; k < n && board[i][n] == 'X'; k++ {
					flag = true
					board[i][k] = '.'
				}

				for k := i + 1; k < m && board[k][j] == 'X' && !flag; k++ {
					board[k][j] = '.'
				}
				res++
			}
		}
	}

	return res

}
